package com.estore.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

public class Product implements Serializable {
    // 添加 serialVersionUID
    private static final long serialVersionUID = 1L;

    private String id;
    private String name;
    private double price;
    private int stock;
    private String description;
    private Set<String> tags;

    // 构造函数 - 接收标签集合
    public Product(String id, String name, double price, int stock, Set<String> tags) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
        this.tags = tags != null ? tags : new HashSet<>();
        this.description = String.valueOf(stock);
    }

    // 构造函数 - 不传入标签
    public Product(String id, String name, double price, int stock) {
        this(id, name, price, stock, new HashSet<>());
    }

    // 原有的构造函数（为了兼容）
    public Product(String id, String name, double price, String description) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.description = description;
        this.tags = new HashSet<>();
        this.stock = 0;
    }

    // getter 和 setter 方法
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Set<String> getTags() {
        return tags;
    }

    public void setTags(Set<String> tags) {
        this.tags = tags != null ? tags : new HashSet<>();
    }

    @Override
    public String toString() {
        String baseInfo = String.format("商品ID: %s | 名称: %s | 价格: ¥%.2f | 库存: %d",
                id, name, price, stock);

        if (tags != null && !tags.isEmpty()) {
            return baseInfo + " | 标签: " + tags;
        } else {
            return baseInfo;
        }
    }
}
